<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

    class companymodel extends CI_Model{

        function __construct()
        {
            parent::__construct();
        }
        public function getAllCompany()
        {
            $q = $this->db->get('v_company');
            if($q->num_rows > 0 )
            {
                foreach ($q ->result() as $row )
                {
                    $data[] = $row ;
                }
            }
            return $data;
        }
        public function record_count() {
            return $this->db->count_all("v_company");
        }
        /*public function record_count() {
            return $this->db->count_all("v_company");
        }*/
        
        public function fetch_companies($limit, $start, $sort_by, $asds, $terms) {
            $this->db->limit($limit, $start);
            $this->db->order_by($sort_by, $asds); 
            if (isset($terms))
            {
                $this->db->like('id', $terms);
                $this->db->or_like('name', $terms); 
                $this->db->or_like('nama_pic', $terms); 
            }else
            {
                
            }
            $query = $this->db->get("v_company");
            if ($query->num_rows() > 0) {
                foreach ($query->result() as $row) {
                    $data[] = $row;
                }
                return $data;
            }
            return false;
        }
        
    }